<%@ page contentType="text/html; charset=UTF-8" language="java" import="java.sql.*" errorPage="errorPage.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>
<html xmlns="http://www.w3.org/1999/xhtml">

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>留言板管理</title>
<link href="css/aStyles.css" rel="stylesheet" type="text/css" />
<base href = <%=basePath%>/>
</head>

<% 	User adm  =(User) session.getAttribute("Admin");  
	if (adm == null){
		response.sendRedirect(path + "/index.jsp");
	}
%>



<%@ page import="util.*" %>
<%@ page import="org.w3c.dom.*" %>
<%@ page import="java.io.*"%>
<%@ page import="orm.*" %>
<%@ page import="java.util.ArrayList"  %>
<%@ page import="java.util.Date" %>
<%@ page import="java.text.SimpleDateFormat" %>


<% Date dt=new Date();
   SimpleDateFormat matter1=new SimpleDateFormat("yyyy-MM-dd");
ReadXml readmessage = new ReadXml();
ArrayList nodelist = readmessage.getAll(new File(application.getRealPath(request.getRequestURI())).getParentFile().getParentFile().getParent()
 +"\\xml\\message.xml");
%>

<body>
<!-- CONTAINER START -->
<div id = "container">
<!-- HEADER START -->
        <div id = "top">
        	<div id = "navigation">
            	<html:link page="/admi/admi.jsp" styleClass = "link">&nbsp;&nbsp;&nbsp;&nbsp;首页</html:link>
                <html:link page="/admi/notice.jsp" styleClass = "link">&nbsp;&nbsp;&nbsp;&nbsp;通知</html:link>
                <html:link page="/admi/accMan.jsp" styleClass = "link">&nbsp;&nbsp;&nbsp;&nbsp;帐户管理</html:link>
                <html:link page="/admi/message.jsp" styleClass = "link">&nbsp;&nbsp;&nbsp;&nbsp;留言板管理</html:link>
            </div>
</div>
        <!-- HEADER END -->
        
    	<!-- LOGIN START -->
        <div id = "login">
        	<html:link page="" styleClass="viewTest">·查看当前考试</html:link>
          	<p><html:link page="/admi/admModifyPwd.jsp" styleClass="modifyPwd">·修改密码</html:link></p>
            <p><html:link forward="logout" styleClass="logout">·注销登录</html:link></p>
  		</div>
        <!-- LOGIN END -->
        
        <!-- CLOCK START -->
  		<div id = "clock">
  			<iframe src="index/clock.html" height="407" width="296" frameborder="0" scrolling="no"
            		marginheight="0" marginwidth="0" id="clockFrame" name="clockFrame"></iframe>
		</div>
        <!-- CLOCK END -->
        
        <!-- MAIN START -->
      	<div id = "main" class="text" >
   	  	  <center><br /><br />≡留言板≡<br />
   		  		<table width="80%" border = "1" style="font-size:18px;">
	                <tr>
	                	<td width="120" >标题</td>
	                    <td width="60" >发布人</td>
	                    <td width="230" >内容</td>
	                    <td width="90" >操作</td>
	                </tr>
	                
	                <%
	                String title = "",message ="",sender = "";
	                 %>
	                 
	                <%for(int i =0 ;i < nodelist.size();i++){
	                	System.out.println(nodelist.size());
	                	Node temp = (Node)nodelist.get(i);
	                	NodeList templist = temp.getChildNodes();
	                	for(int j = 0;j < templist.getLength();j++){
	                		if(templist.item(j) instanceof Element){
	                			if(templist.item(j).getNodeName().equals("title")){
                					title = templist.item(j).getTextContent();
                				}
                				
                				if(templist.item(j).getNodeName().equals("message")){
                					message = templist.item(j).getTextContent();
                				}
                				
                				if(templist.item(j).getNodeName().equals("sender")){
                					sender = templist.item(j).getTextContent();
                				}
                			}
                		}
                				if(message.length() > 0 && sender.length() > 0&& message.length()>0){
	                %>
	                <tr>
	                	<td><%=title%></td>
	                	<td><%=sender %></td>
	                	<td><%=message %></td>
	                	<td align="center">
	                		<a href="deletemessage.jsp?id=<%=i%>">删除</a>"
	                		<a href="updatemessage.jsp?id=<%=i%>">修改</a>"
	                	</td>
	                	
	                </tr>
	                <%} %>
	                <%} %>
                </table>
                
             
                	<form name="sendmessageForm" method ="post" action="sendmessageAction.do">
                	   <table width="80%" >
                		<tr>
                			<td>标题</td>
                			<td>
                				<input type="text" name="title" size="40" maxlength="70"/>
                			</td>
                		</tr>
                		<tr>
                			<td>内容</td>
                			<td>
                				<textarea name="message" cols = "70" rows="10"></textarea>
                			</td>
                		</tr>
                		<tr>
                			<td align="center" colspan = "2">
                				<input type="submit" value="发送"/>
                				<input type="reset" value="重写"/>
                			</td>
                			
                		</tr>
                		 </table>
                	</form>
               
    	</center>
	</div>
	
	
	
	<%/*
	String mytitle = (String)request.getAttribute("title");
	String mymessage = (String)request.getAttribute("message");
	System.out.println(new File(application.getRealPath(request.getRequestURI())).getParentFile().getParentFile().getParent()
 +"\\xml\\message.xml");
	
	if(mytitle != null && mymessage != null){
	System.out.println(new File(application.getRealPath(request.getRequestURI())).getParentFile().getParentFile().getParent()
 +"\\xml\\message.xml");
		WriteXml.AppendChild(new File(application.getRealPath(request.getRequestURI())).getParentFile().getParentFile().getParent()
 +"\\xml\\message.xml",matter1.format(dt),"Message",mytitle,mymessage,adm.getUsername());
	}*/
	 %>
   	<!-- MAIN END -->
        
   	<!-- FOOTER START -->
   	<div id = "footer">
  </div>
   	<!-- FOOTER END -->
        
</div>
    <!-- CONTAINER END -->
    
</body>
</html>
